package com.indicator.spring.controller;

import com.indicator.spring.controller.request.NewCoffeeRequest;
import com.indicator.spring.model.Coffee;
import com.indicator.spring.service.CoffeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 超
 * Create by fengc on  2022/9/22 20:10
 */
@RestController
@RequestMapping("/coffee")
@Slf4j
public class CoffeeController {

    @Resource
    private CoffeeService coffeeService;

    @PostMapping("/")
    @ResponseStatus(HttpStatus.CREATED)
    public Coffee addCoffee(@RequestBody NewCoffeeRequest newCoffeeRequest) {
        return coffeeService.saveCoffee(newCoffeeRequest.getName(),newCoffeeRequest.getPrice());
    }

    @GetMapping("/")
    public List<Coffee> getAll() {
        return coffeeService.getAll();
    }
}
